home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
adjram41.zip
/
ADJRAM.C
next >
Wrap
C/C++ Source or Header
|
1988-05-15
|
53KB
|
1,509 lines
/* Adjustable Ram Disk
(c) Copyright 1986,1987 by Gary Cramblitt. All Rights Reserved.
v2.2 1 Jul 86 Initial version
v2.3 24 Aug 86 Bug. FAT media byte not updated properly.
v2.4 29 Aug 86 If current drive is memory disk drive, reset current
directory on exit.
v2.5 30 Aug 86 Increase FAT to permit max size of 2043K;
Increase size of root directory to 128 entries;
Start code for /E option (Expanded Memory Support)
v3.0 30 Aug 86 Finish code for /E option.
v3.1 2 Oct 86 Fix shrink bug. Not packing subdirectories properly
v3.2 18 Oct 86 Allow SIZE= clause for AMDISK. Also allow drive letters
A through L.
v4.0 3 Jan 87 Add reserved conventional memory support as
R:xxxx:nn option.
Full support for expanded memory mixed with conventional
memory.
Max size of memory disk based upon available memory and
cluster size.
User requested expansion or shrinkage automatically
adjusted to within limits and rounded to nearest
memory block boundary.
In expanded memory, use larger block size (64K) to avoid
excessive usage of EMM handles.
Display Memory Block Table only if /t option specified.
Bug. Stop processing directory when first "never_used"
flag is encountered.
Bug in DeSmet free() routine. Causes memory overflo.
Calculate stack space manually instead.
Restrict program size to under 32K.
Clean up error reporting. Tell user if error has
corrupted the memory disk.
v4.1 15 May 88 Restrict reserved memory to above segment a000.
Initialize reserved memory when block is allocated.
For program usage, see the last routine.
A few definitions:
1. CONVENTIONAL MEMORY is that memory directly addressable
by the 8088 or 8086 CPU and controlled by DOS. On the
IBM PC, it falls below 640K.
2. RESERVED MEMORY is also directly addressable by the
8088 or 8086, but it is not controlled by DOS. On
the IBM PC, it falls above 640K and below 1MB. It
is usually reserved for use by the PC's BIOS. If your
machine has memory mapped to addresses between 640K and
1MB and that memory is not needed for any other purpose,
and it is directly addressable by the CPU (no special
"paging" or "mapping" required to access it), then
ADJRAM can use it via the R option. See .DOC
3. EXTENDED MEMORY is addressed above 1MB. It is only
available on AT type machines (80286 or 80386 CPUs).
It is not currently supported by ADJRAM.
4. EXPANDED MEMORY is memory conforming to the Lotus/
Intel/Microsoft Expanded Memory Specification. It
is supported by ADJRAM if you have the EMM loaded.
This program is coded in DeSmet C v2.4. Any function beginning
with underscore (_) is a non-standard routine from the DeSmet library.
They are:
_showcs()
Synopsis: unsigned _showcs()
Returns the current value of CS.
_showds()
Synopsis: unsigned _showds()
Returns the current value of DS (= SS in DeSmet C).
_showsp()
Synopsis: char *_showsp()
Returns the current value of SP.
_setsp()
Synopsis: void _setsp(newStackValue);
unsigned newStackValue;
Sets the SP register to the specified value.
_memory()
Synopsis: char *_memory()
Returns a pointer to the first byte of free memory past
the end of initialized memory (global data).
_peek()
Synopsis: char _peek(offset,segment)
char *offset;
unsigned segment;
Returns the byte at specified far address.
_doint()
Synopsis: set any or all of the externs
_rax,_rbx,_rcx,_rdx,_rsi,_rdi,_res,_rds
followed by
_doint(interrupt number);
Performs the specified interrupt with the specified
registers set from the externs.
After the call, _rax, etc. can be used. _carryf
and _zerof are extern char variables set to 1 if
the carry or zero flag is set.
In addition, the following routines are semi_standard, and may have
slightly different implementations with your compiler:
strncmp()
Synopsis: char *strncmp(leftstring,rightstring,max)
char *leftstring, *rightstring
int max
strncmp() compares up to a specified number of chars
in two strings. It returns 0 if the specified number
of characters in the string are the same.
*/
/* ==== Definitions ==== */
/* ---- Overall Definitions ---- */
#define true 1
#define false 0
/*
---- To compile without LOTUS/INTEL/Microsoft Expanded Memory
support, change the "1" to "0" in the next statement. Will
save about 1500 bytes in EXE file.
*/
#define em_support 1 /* compile for EM support */
/* ---- To compile without reserved memory support, change
the "1" to "0" in the next statement.
*/
#define rm_support 1 /* compile for reserved memory */
#define debug 0 /* compile with debug stmts */
/* ---- Other customizable symbols */
#define start_rm_addr 0xa000 /* start of reserved memory */
/*
The following symbols must correspond to the same symbols in
file amdisk.asm. If one is changed, so must the other.
This is because the first memory block may not be
deallocated.
*/
#define def_size_K 64 /* default to 64K RAM disk */
#define min_size_K (boot_sec.mem_blk_table[0].siz/sec_per_K)
#define min_size_sec boot_sec.mem_blk_table[0].siz
#define em_sec_per_blk 512 /* increment in 256K Expanded */
/* Memory blocks */
#define cnv_sec_per_blk 64 /* increment in 32K conventional*/
/* memory blocks */
/*
---- Disk definitions. Note: These constants should be made into
variables or functions if this program's algorithms need to
be generalized to disks of any type, especially high density disks.
Since this program works only in conjunction with amdisk.asm,
it is OK to make them constants here.
*/
#define bytes_per_sec 512 /* 512 bytes per sector */
#define par_per_sec (512/16)
/* 32 paragraphs per sector */
#define sec_per_K (1024/512)
/* sectors per 1024 bytes */
#define dir_per_sec (512/sizeof(struct dir_entry))
/* directory entries per sector */
#define K_per_blk (sec_per_blk/sec_per_K)
/* K per memory block */
#define em_pag_per_blk (K_per_blk/16)
/* 16K EM pages per mem block */
#define max_clu